#!/bin/bash

# 应用名称
APP_NAME="jzsxxzx"
# 应用版本
APP_VERSION="1.0.0"
# JAR文件名
JAR_NAME="${APP_NAME}-${APP_VERSION}.jar"
# JVM参数
JVM_OPTS="-Xms512m -Xmx1024m"
# 配置文件路径
CONFIG_PATH="./config/application.properties"

# 检查是否已经运行
pid=`ps -ef | grep $JAR_NAME | grep -v grep | awk '{print $2}'`
if [ -n "$pid" ]; then
    echo "$APP_NAME is already running (pid=$pid)"
    exit 1
fi

# 启动应用
echo "Starting $APP_NAME..."
nohup java $JVM_OPTS -jar $JAR_NAME --spring.config.location=file:$CONFIG_PATH > logs/startup.log 2>&1 &

# 等待一段时间确认应用是否启动成功
sleep 5

# 检查是否启动成功
pid=`ps -ef | grep $JAR_NAME | grep -v grep | awk '{print $2}'`
if [ -n "$pid" ]; then
    echo "$APP_NAME started successfully (pid=$pid)"
else
    echo "$APP_NAME failed to start, please check logs/startup.log for more details"
    exit 1
fi
